package cn.edu.java.collection;

import java.util.Vector;

public class VectorDemo {
    public static void main(String[] args) {
        // 创建一个 Vector 实例
        Vector<String> vector = new Vector<>();

        // 添加元素到 Vector
        vector.add("Apple");
        vector.add("Banana");
        vector.add("Orange");

        // 获取 Vector 的大小
        System.out.println("Size of vector: " + vector.size());

        // 遍历 Vector 并打印元素
        System.out.println("Elements in vector:");
        for (String element : vector) {
            System.out.println(element);
        }

        // 检查 Vector 是否包含指定元素
        boolean containsApple = vector.contains("Apple");
        System.out.println("Vector contains 'Apple': " + containsApple);

        // 获取指定索引位置的元素
        String elementAtIndex = vector.get(1);
        System.out.println("Element at index 1: " + elementAtIndex);

        // 修改指定索引位置的元素
        vector.set(0, "Mango");
        System.out.println("Modified vector:");
        for (String element : vector) {
            System.out.println(element);
        }

        // 删除指定元素
        vector.remove("Banana");
        System.out.println("Vector after removing 'Banana':");
        for (String element : vector) {
            System.out.println(element);
        }

        // 清空 Vector
        vector.clear();
        System.out.println("Size of vector after clearing: " + vector.size());


    }
}
